﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using SharpSvn;

namespace TestSharpSvn
{
    /// <summary>
    /// SvnCommand 的摘要说明
    /// </summary>
    public class SvnCommand : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            var path = "e:\\worktest\\svn\\test\\";
            using (SvnClient client = new SvnClient())
            {
                string configPath = Path.Combine(Path.GetTempPath(), "sharpsvn");
                if (!Directory.Exists(configPath))
                {
                    Directory.CreateDirectory(configPath);
                }
                client.LoadConfiguration(configPath, true); 
                client.Authentication.DefaultCredentials = new NetworkCredential("guest", "");
                // Checkout the code to the specified directory
                client.CheckOut(new Uri("https://ctf.open.collab.net/svn/repos/sharpsvn/"), path);

                // Update the specified working copy path to the head revision
                client.Update(path);
                SvnUpdateResult result;
                client.Update(path, out result);


                // client.Move("c:\\sharpsvn\\from.txt", "c:\\sharpsvn\\new.txt");

                // Commit the changes with the specified logmessage
                // SvnCommitArgs ca = new SvnCommitArgs();
                //  ca.LogMessage = "Moved from.txt to new.txt";
                // client.Commit("c:\\sharpsvn", ca);
                client.Commit(path);
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write("success");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}